package Top200;

import common.ListNode;

/**
 * @author zhangmin
 * @create 2022-02-27 14:40
 */
public class reverseBetween92 {
    ListNode succ=null;
    //反转head开头的前n个节点
    ListNode reverseN(ListNode head,int n){
        if (n==1){
            succ=head.next;
            return head;
        }
        ListNode next=reverseN(head.next,n-1);
        head.next.next=head;
        head.next=succ;
        return next;
    }
    public ListNode reverseBetween(ListNode head, int left, int right) {
        if (left==1){
            return reverseN(head,right);
        }
        head.next=reverseBetween(head.next,left-1,right-1);
        return head;
    }
}
